package com.feiyu.service.impl;

import com.feiyu.aop.FeiYuLog;
import com.feiyu.mapper.EmpMapper;
import com.feiyu.pojo.Emp;
import com.feiyu.pojo.PageBean;
import com.feiyu.service.EmpService;
import com.github.pagehelper.Page;
import com.github.pagehelper.PageHelper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.time.LocalDate;
import java.util.List;

@Service
public class EmpServiceImpl implements EmpService {

    @Autowired
    private EmpMapper empMapper;

    @Override
    public PageBean page(Integer page, Integer pageSize,
                         String name, Short gender,
                         LocalDate start,LocalDate end) {

        //设置分页参数
        PageHelper.startPage(page, pageSize);
        //分页查询
        List<Emp> empList = empMapper.list(name,gender,start,end);

        //获取分页结果
        Page<Emp> p = (Page<Emp>) empList;

        //封装PageBean
        PageBean pageBean = new PageBean(p.getTotal(), p.getResult());
        return pageBean;


    }

    /**
     * 登录
     * @param emp
     */

    @Override
    public Emp login(Emp emp) {

       Emp  empLogin =empMapper.login(emp);
       return   empLogin;
    }

    /**
     * 删除
     * @param ids
     */
    @FeiYuLog
    @Override
    public void deleteByIds(String[] ids) {


        empMapper.deleteByIds(ids);
    }


}
